﻿'
' Copyright (c) Microsoft Corporation. All rights reserved.
'
' This source code is subject to terms and conditions of the Microsoft Public
' License (Ms-PL). A copy of the license can be found in the license.htm file
' included in this distribution.
'
' You must not remove this notice, or any other, from this software.
'
Public Class VbViewEngine
    Implements IViewEngine

    Function FindView(ByVal controllerContext As ControllerContext, ByVal viewName As String) As ViewEngineResult
        Dim controllerName = controllerContext.RouteData.GetRequiredString("controller")
        Dim controllerType = controllerContext.Controller.GetType()
        Dim viewTypename = controllerType.FullName.Split(".")(0) + ".Views." + controllerName + "." + viewName
        Dim viewType = controllerType.Assembly.GetType(viewTypename, False, True)

        If viewType Is Nothing Or Not GetType(VbView).IsAssignableFrom(viewType) Then
            Return New ViewEngineResult(New String() {})
        End If

        Dim view = Activator.CreateInstance(viewType)
        Return New ViewEngineResult(view, Me)
    End Function

    Public Function FindPartialView(ByVal controllerContext As ControllerContext, ByVal partialViewName As String, ByVal useCache As Boolean) As ViewEngineResult Implements IViewEngine.FindPartialView
        Return FindView(controllerContext, partialViewName)
    End Function

    Public Function FindView(ByVal controllerContext As ControllerContext, ByVal viewName As String, ByVal masterName As String, ByVal useCache As Boolean) As ViewEngineResult Implements IViewEngine.FindView
        Return FindView(controllerContext, viewName)
    End Function

    Public Sub ReleaseView(ByVal controllerContext As ControllerContext, ByVal view As IView) Implements IViewEngine.ReleaseView
    End Sub
End Class
